************************************************************************************************************************************************
********** THIS .DO FILE PRODUCES FIGURE 2 (Visual presentation of RD Estimates of the effect of a left-wing mayor on social spending) *********
************************************************************************************************************************************************

clear *

* call program to make rd graphs
do "${root}/codes/analysis/programs/rdgraph_prog.do"

*** PRODUCE GRAPHS

use "${root}/data/processed/final_sample.dta", clear
set scheme plotplain

* add back means to residualized variables, for better interpretation
foreach variable in social_exp_avg_share social_exp_avg_pc {
	sum `variable'
	replace res_`variable'=res_`variable'+`r(mean)'
}

replace res_social_exp_avg_pc = res_social_exp_avg_pc/100

keep if baseline_sample == 1


* social expenditures share
* social expenditures
rdgraph res_social_exp_avg_share margin_mayor_left, title("RD Plot - social expenditures share") name(social_exp_baseline) ytitle("Social expenditures share") yaxisopt("ylabel(55(1)63) yscale(range(55 63))") pos(11) legend(yes)

* social expenditures share in lame duck subsample
preserve 
keep if lame_duck==1
rdgraph res_social_exp_avg_share margin_mayor_left, title("RD Plot - social expenditures share") name(social_exp_lameduck) ytitle("Social expenditures share") yaxisopt("ylabel(55(1)63) yscale(range(55 63))") pos(11) 
restore

* social expenditures share in oil windfalls subsample
preserve 
keep if oil_sample==1
rdgraph res_social_exp_avg_share margin_mayor_left, title("RD Plot - social expenditures share") name(social_exp_oil) ytitle("Social expenditures share") yaxisopt("ylabel(55(1)63) yscale(range(55 63))") pos(11) 
restore


* social expenditures per capita
rdgraph res_social_exp_avg_pc margin_mayor_left, title("RD Plot - social expenditures per capita") name(social_exp_pc_baseline) ytitle("Log social exp. per capita") yaxisopt("ylabel(7.22(0.02)7.45) yscale(range(7.22 7.45))") pos(11)

* social expenditures per capita in lame duck subsample
preserve 
keep if lame_duck==1
rdgraph res_social_exp_avg_pc margin_mayor_left, title("RD Plot - social expenditures per capita") name(social_exp_pc_lameduck) ytitle("Log social exp. per capita") yaxisopt("ylabel(7.22(0.02)7.45) yscale(range(7.22 7.45))") pos(11)
restore

* social expenditures per capita in oil windfalls subsample
preserve 
keep if oil_sample==1
rdgraph res_social_exp_avg_pc margin_mayor_left, title("RD Plot - social expenditures share") name(social_exp_pc_oil) ytitle("Log social exp. per capita") yaxisopt("ylabel(7.22(0.02)7.45) yscale(range(7.22 7.45))") pos(11)
restore


graph combine social_exp_baseline social_exp_pc_baseline, xcommon b1(Left margin of victory, size(medlarge)) xsize(6) ysize(2) iscale(1.5)
graph export "${root}/results/figures/social_exp_baseline.pdf", replace

graph combine social_exp_lameduck social_exp_pc_lameduck, xcommon b1(Left margin of victory, size(medlarge)) xsize(6) ysize(2) iscale(1.5)
graph export "${root}/results/figures/social_exp_lameduck.pdf", replace
 
graph combine social_exp_oil social_exp_pc_oil, xcommon b1(Left margin of victory, size(medlarge)) xsize(6) ysize(2) iscale(1.5)
graph export "${root}/results/figures/social_exp_oil.pdf", replace
